home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDElapsed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.7 KB  |  142 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDElapsed - An XFCN to report elapsed time on disc
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDElapsed.c
  11.     link -sn Main=CDElapsed -sn STDIO=CDElapsed ∂
  12.          -sn INTENV=CDElapsed -rt XFCN=42 ∂
  13.          -m CDElapsed CDElapsed.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. OSErr    ReadQ(short, long *, long *, long *, long *);
  28.  
  29. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  30.  
  31.  
  32. /************************************************************************
  33.  *
  34.  *  Function:        CDElapsed
  35.  *
  36.  *  Purpose:        return the elapsed time on this disc.
  37.  *
  38.  *  Returns:        either 0, or an error
  39.  *                    if it's a negative number, it's an error
  40.  *
  41.  *  Side Effects:
  42.  *
  43.  *  Description:    We need no parameters:
  44.  *                    Get the ioRefNum that we got from previously calling
  45.  *                    CDOpen(), using the famous global.
  46.  *                    call the driver with a READQ call to find out
  47.  *                    how absolute minute, second, block elapsed.
  48.  *
  49.  ************************************************************************/
  50. pascal void
  51. CDElapsed(paramPtr)
  52. XCmdBlockPtr    paramPtr;
  53. {
  54.     Str31    returnString;
  55.     OSErr    result;
  56.     short    ioRefNum;
  57.     Handle    refHandle;
  58.     long    ElapsedDisc[4];    /* minute, second, block */
  59.     
  60.     /* Must be no parameters */
  61.     if ((paramPtr->paramCount) != 0)
  62.     {
  63.         /* Report error in parameters by returning -1 */
  64.         NumToStr(paramPtr, (long) -1, &returnString);
  65.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  66.         return;
  67.     }
  68.     
  69.     /* Get the global ioRefNum and convert it. */
  70.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  71.     ioRefNum = atoi(*(refHandle));
  72.     DisposHandle(refHandle);
  73.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  74.     
  75.     
  76.     result = ReadQ(ioRefNum, &ElapsedDisc[0], &ElapsedDisc[1], &ElapsedDisc[2], &ElapsedDisc[3]);
  77.     
  78.     if (result == noErr)
  79.     {
  80.         /* convert each value to a string, concatenate, & return. */
  81.         FormatString(&returnString, ElapsedDisc, 4);
  82.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  83.     }
  84.     else
  85.     {
  86.         /* We got an error. Convert result to string & return it as error */
  87.         NumToStr(paramPtr, (long) result, &returnString);
  88.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  89.     }
  90. }
  91.  
  92. /************************************************************************
  93.  *
  94.  *  Function:        ReadQ
  95.  *
  96.  *  Purpose:        return current track & elapsed time for current track
  97.  *
  98.  *  Returns:        OSErr.  Probably either
  99.  *                        noErr        everything's hunky-dory!
  100.  *                        paramErr    you messed up the call somehow.
  101.  *
  102.  *  Side Effects:    none
  103.  *
  104.  *  Description:    Simply call the driver with a READQ call.  The absolute
  105.  *                    minute, second, block come back in BCD.  Convert them
  106.  *                    to decimal and return them.
  107.  *
  108.  ************************************************************************/
  109. OSErr
  110. ReadQ(refNum, trackNo, minute, second, block)
  111. short    refNum;
  112. long    *trackNo;
  113. long    *minute;
  114. long    *second;
  115. long    *block;
  116. {
  117.     CDParam    myPB;
  118.     OSErr    result;
  119.     
  120.     myPB.ioCompletion = 0;
  121.     myPB.ioNamePtr = (char *) 0;
  122.     myPB.ioVRefNum = 1;
  123.     myPB.ioCRefNum = refNum;
  124.     myPB.csCode = READQ;
  125.     
  126.     result = PBControl(&myPB, false);
  127.     
  128.     if (result == noErr)
  129.     {
  130.         *trackNo = (long) BCD2DECIMAL(myPB.csParam[1]);
  131.         *minute = (long) BCD2DECIMAL(myPB.csParam[6]);
  132.         *second = (long) BCD2DECIMAL(myPB.csParam[7]);
  133.         *block = (long) BCD2DECIMAL(myPB.csParam[8]);
  134.     }
  135.     return result;
  136. }
  137.  
  138.  
  139.  
  140. /* C routines for HyperCard callbacks */
  141. #include <XCmdGlue.inc.c>
  142.